package org.fightingliu.demo.service.impl;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.indices.GetIndexResponse;
import co.elastic.clients.elasticsearch.indices.IndexState;
import com.alibaba.fastjson2.JSONObject;
import org.fightingliu.demo.service.ElasticsearchSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

/**
 * @author : LiuChao
 * @description : TODO
 * @date : 2025-05-04 14:16:38
 */
@Service
public class ElasticsearchServiceImpl implements ElasticsearchSevice {
    @Autowired
    ElasticsearchClient elasticsearchClient;

    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;

    @Override
    public String getIndices() {
        Map<String, IndexState> result;
        try {
            GetIndexResponse getIndexResponse = elasticsearchClient.indices().get(req -> req.index("*"));
            result = getIndexResponse.result();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return JSONObject.toJSONString(result);
    }
}
